module.exports = function ($scope, $state, $stateParams,$resource,$modal,toaster) {
  /* 分页
      * ========================================= */
  $scope.maxSize = 5;             //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10         //每页显示几条
  $scope.searchform = {};
  $scope.getlist = function () {
      var para = {
          pageNo:$scope.bigCurrentPage, 
          pageSize:$scope.itemsPerPage
      };
      para = angular.extend($scope.searchform, para);
      $resource('/api/as/ggc/reviewGuide/findDirectoryInfoList', {}, {}).
      save(para,function(res) {
          if (res.errcode !== 0) {
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          $scope.objs = res.data.results;
          $scope.bigTotalItems = res.data.totalRecord;
      })
  };
   
  $scope.getlist(); 
  $scope.toinfo= function (index) {
      $state.go('app.guide_infos', {'directory_pdf' : $scope.objs[index].directory_pdf, 'flag' : 'guanfang'});
      // $scope.item = $scope.objs[index];			
      // var modalInstance = $modal.open({
      //   template: require('../views/guide_info.html'),
      //   controller: 'guide_info',
      //   size: 'lg',
      //   resolve: {
      //     // str: function () {
      //     //   return $scope.str;
      //     // },
      //   }
      // });
      // modalInstance.result.then(function (showResult) {	
      //     $scope.getlist();
      // });
  }
  // $('a.media').media({width:800, height:600});    
  $scope.edit= function (index) {
    $scope.flag = 'edit';
    $scope.item = $scope.objs[index];	
    var modalInstance = $modal.open({
        template: require('../views/projectGuideInfo.html'),
        controller: 'projectGuideInfos',
        size: 'lg',
        resolve: {
          id: function () {
            return $scope.item.id;
          },
          flag: function () {
              return $scope.flag;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.getlist();
      });
}
$scope.issue= function (index) {    
    console.log($scope.objs[index].id) ;          
    if(confirm('是否发布该条指南？')){
        $resource('/api/as/ggc/reviewGuide/updateDirectoryUp', {}, {}).save({'id':$scope.objs[index].id}, function(res){			              
          if(res.errcode === 0 || res.errcode === 10003){
              toaster.success({title:"",body:'发布成功'});
              $scope.getlist();
          }else{
              toaster.error({title:"",body:res.errmsg});
          }
      });
    }		
}

  $scope.offline= function (index) {    
      if(confirm('确定下线该指南吗？')){
          $resource('/api/as/ggc/reviewGuide/updateDirectoryDown', {}, {}).save({'id':$scope.objs[index].id}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  toaster.success({title:"",body:'下线成功'});
                  $scope.getlist();
              }else{
                  toaster.error({title:"",body:res.errmsg});
              }
          });
      }		
  }
  
  
};
